#ifndef UPLOADTASK_H
#define UPLOADTASK_H

#include <QFile>
#include <QString>

#include <widget/dataprogress.h>


struct UploadFileInfo
{
    QString md5;
    QFile* file;
    QString fileName;
    qint64 size;
    QString path;
    bool isUpload;
    DataProgress* dp;
};

class UploadTask
{
public:
    static UploadTask* getInstance();

    bool isEmpty();
    bool isUpload();

    UploadFileInfo* takeTask();

    void dealUploadTask();

    void clearList();

    int appendUploadList(QString path);
private:
    UploadTask() = default;
    ~UploadTask() = default;
    UploadTask(const UploadTask& obj) = delete; //拷贝构造
    UploadTask& operator=(const UploadTask& obj) = delete;//拷贝赋值
    UploadTask(UploadTask&& obj) = delete;//移动构造
    UploadTask& operator=(UploadTask&& obj) = delete;//移动赋值

    static UploadTask* instance;
signals:
    void listEmptySignal();
private:
    class AutoRelease
    {
    public:
        AutoRelease() = default;
        ~AutoRelease()
        {
            if(instance == nullptr) return;
            delete instance;
            instance = nullptr;
        }
    };
private:
    static AutoRelease _at;

    QList<UploadFileInfo*> list;
};

#endif // UPLOADTASK_H
